package Algorithm.Othes;
//https://leetcode-cn.com/problems/replace-all-s-to-avoid-consecutive-repeating-characters/
//1576. 替换所有的问号
public class Leetcode1576_替换所有的问号 {
    class Solution {
        public String modifyString(String s) {
            StringBuilder builder = new StringBuilder();
            for(int i = 0; i < s.length(); i++){
                char c = s.charAt(i);
                if(c != '?'){
                    builder.append(c);
                    continue;
                }

                for(int j = 0; j < 26; j++){
                    char temp = (char)('a' + j);
                    if(i>0 && builder.charAt(i-1) == temp){
                        continue;
                    }

                    if(i < s.length() - 1 && s.charAt(i+1) == temp){
                        continue;
                    }

                    builder.append(temp);
                    break;
                }
            }

            return builder.toString();
        }
    }
}
